package org.list;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;

public class list1 {
    public static void main(String[] args) {
        ArrayList<Object> list = new ArrayList<>();
        list.add("wsq");
        list.add("wsq");
        list.add(10);
//        指定位置插入
        list.add(1,"sss");
//        addAll:添加多个元素
        Collections.addAll(list,"tom","jack");
        list.addAll(Arrays.asList("mary","curry"));
        System.out.println(list);
//        替换
        list.set(0,"zzz");
//        返回指定区间数据(左闭右开)
        System.out.println("指定区间数据:"+list.subList(2,5));
//        contains:查找元素是否存在
        boolean wsq = list.contains("wsq");
        System.out.println(wsq);
//        containsAll:查找多个元素是否都存在
        boolean b = list.containsAll(Arrays.asList("mary", "curry"));
        System.out.println(b);
        System.out.println(list.size());
        list.remove(1);
        list.remove((Integer)10);
//        removeAll：删除多个元素
        list.removeAll(Arrays.asList("mary", "curry"));
//        System.out.println(list);
//        遍历
        Iterator<Object> iterator = list.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println("遍历结果:"+next);
        }
        list.add(new Dog("pp",2));
        list.add(new Dog("tt",3));
        System.out.println("-------------");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("-------------");
        for (Object o : list) {
            System.out.println(o);
        }
    }
}
class Dog {
    private String name;
    private int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}